﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SDT.Admin.ViewModels.ArticleEditViewModel>" %>

<%@ Import Namespace="SDT.Lib.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Tin tức
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server">
    Thêm mới bài viết
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="Message" runat="server">
    <%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Toolbar" runat="server">
    <td>
        <%= Html.Toolbar("Quay về", "/Article", "back") %>
    </td>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%if (ViewData["MessageInfo"] == null)
      { %>
    <% using (Html.BeginForm("Create", "Article", FormMethod.Post, new { id = "adminForm", enctype = "multipart/form-data" }))
       {%>
    <%= Html.ValidationSummary(true)%>
    <table class="admintable" width="100%">
        <tbody>
            <tr>
                <td class="key">
                    Chuyên mục
                </td>
                <td>
                    <%=Html.DropDownList("CatID", new SelectList(Model.Categories, "ID", "Name").ToList(), "-- Chuyên mục --", new { @class = "title" })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Tiêu đề (<font color="red">*</font>)
                </td>
                <td>
                    <%=Html.TextBoxFor(m=>m.Article.Title, new { style = "width:795px;", @class="required" })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Tóm tắt (<font color="red">*</font>)
                </td>
                <td>
                    <%=Html.TextAreaFor(m => m.Article.Summary, new { style = "width:795px; height:124px;",cols=120, @class="required" })%>
                </td>
            </tr>
            <tr>
                <td class="key">
                    Ảnh đại diện
                </td>
                <td>
                    <input type="file" name="ArticleImage" id="ArticleImage" />
                </td>
            </tr>
            <tr>
                <td class="key">Chọn tag</td>
                <td>
                    <%= Html.TextBox("TagName", string.Empty, new { style = "width:350px" })%>
                    <%= Html.Hidden("TagID")%> (<font color="red">*</font>)Cho phép chọn nhiều tag, mỗi tag cách nhau bằng dấu ","
                </td> 
            </tr>
                       
            <tr>
                <td class="key">
                    Trạng thái hiển thị
                </td>
                <td>
                    <%= Html.RadioButton("PublishYN", true, new { @checked = "checked" })%>
                    Đăng tin
                    <%= Html.RadioButton("PublishYN", false) %>
                    Không đăng
                </td>
            </tr>
            <tr>
                <td class="key">
                    Tin nổi bật
                </td>
                <td>
                    <%= Html.RadioButton("HotYN", true, new { @checked = "checked" })%>
                    Đặt làm tin nổi bật
                    <%= Html.RadioButton("HotYN", false) %>
                    Tin thường
                </td>
            </tr>
            <tr>
                <td class="key">MetaDescription</td>
                <td> <%=Html.TextBoxFor(m=>m.Article.MetaDescription, new { style = "width:795px;"})%></td>
            </tr>
            <tr>
                <td class="key">MetaKeyword</td>
                <td><%=Html.TextBoxFor(m=>m.Article.MetaKeyword, new { style = "width:795px;"})%></td>
            </tr>
            <tr>
                <td class="key">MetaTag</td>
                <td><%=Html.TextBoxFor(m=>m.Article.MetaTag, new { style = "width:795px;"})%></td>
            </tr>
            <tr>
                <td class="key">
                    Nội dung(<font color="red">*</font>)
                </td>
                <td>
                    <%=Html.TextAreaFor(m=>m.Article.ArticleContent, new {cols = 97, rows = 25 })%>
                </td>
            </tr>
            <tr>
                <td class="key">Bài viết cho sự kiện</td>
                <td><%=Html.DropDownList("EventID", new SelectList(Model.Events, "ID", "Title").ToList(), "-- Chọn sự kiện --", new { @class = "title", style="width:300px" })%></td>
            </tr>            
            
            <tr>
                        <td class="key">
                            File đính kèm
                        </td>
                        <td>
                            <table id="frmFile" width="100%" class="adminlist">
                                <tr>
                                    <th>Tên file</th>    
                                    <th>File đính kèm</th>
                                </tr>
                                <tr>
                                    <td><input type="text" id="fileName1" name="fileName1" size="90" /></td>
                                    <td>
                                        <input id="fileInput1" size="25" name="fileInput1" type="file" onchange="check_extension(this.value,'btnSave');" />
                                        &nbsp;<input id="btnAddFile" type="button" value="Thêm" onclick="AddFile();" />
                                    </td>
                                </tr>
                            </table>

                            <script type="text/javascript">
                                var fileIndex = 1;
                                var hash = { '.jpg': 1, '.png': 1, '.gif': 1, '.doc': 1, '.docx': 1, '.xls': 1, '.xlsx': 1, '.zip': 1, '.rar': 1, '.ppt': 1, '.pptx': 1, '.txt:': 1 };
                                function check_extension(filename, submitId) {
                                    var re = /\..+$/;
                                    var ext = filename.match(re).toString().toLowerCase();
                                    var submitEl = document.getElementById(submitId);
                                    if (hash[ext]) {
                                        submitEl.disabled = false;
                                        return true;
                                    } else {
                                    }
                                };
                                function AddFile() {
                                    fileIndex++;
                                    var tag2 = "<td><input id='fileInput" + fileIndex.toString() + "' name='fileInput" + fileIndex.toString() + "' type=\"file\" size='25'  onchange=\"check_extension(this.value,'btnSave');\" /></td>";
                                    var tag1 = "<td><input id='fileName" + fileIndex.toString() + "' name='fileName" + fileIndex.toString() + "' type=\"text\" size='90'/></td>"
                                    var row = "<tr>" + tag1 + tag2 + "</tr>";
                                    $("#frmFile").append(row);
                                };
                            </script>

                        </td>
                    </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" id="btnSave" value="Thêm mới" onclick="return check_extension('ArticleImage','btnSave');" />
                    <input type="reset" id="btnReset" value="Nhập lại" />
                </td>
            </tr>            
        </tbody>
    </table>
    <%}
  } %>

    <script type="text/javascript">
        $(document).ready(function() {
            $("#adminForm").validate();
        });

        var fileIndex = 1;
        var hash = { '.jpg': 1, '.png': 1, '.gif': 1, '.doc': 1, '.docx': 1, '.xls': 1, '.xlsx': 1, '.zip': 1, '.rar': 1, '.ppt': 1, '.pptx': 1, '.txt:':1 };
        function check_extension(filename, submitId) {
            var re = /\..+$/;
            var ext = filename.match(re).toString().toLowerCase();
            var submitEl = document.getElementById(submitId);
            if (hash[ext]) {
                submitEl.disabled = false;
                return true;
            } else {
            }
        }                
        tinyMCE.init({
            mode: "exact",
            elements: "Article_ArticleContent",
            theme: "advanced",
            plugins: "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,paste,imagemanager",
            theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
            theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
            theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            paste_use_dialog: false,
            paste_auto_cleanup_on_paste: true,
            paste_convert_headers_to_strong: false,
            paste_strip_class_attributes: "all",
            paste_remove_spans: true,
            paste_remove_styles: true
        });

        // Start Load du lieu Autocomplete for filed Select tag: Created by Vietlv//
        $("#TagName").autocomplete({
            minLength: 2,
            source: function(request, response) {
                $.ajax({
                    url: "/AjaxData/SearchTag",
                    dataType: "json",
                    data: {
                        keyword: extractLast(request.term)
                    },
                    success: function(data) {
                        response($.map(data, function(item) {
                            return {
                            label: item.Keyword,
                            value: item.Keyword,
                                id: item.ID
                            }
                        }));
                    }
                });
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var terms = split(this.value);
                // remove the current input
                terms.pop();
                // add the selected item
                terms.push(ui.item.value);
                // add placeholder to get the comma-and-space at the end
                terms.push("");
                this.value = terms.join(", ");

                var termsk = split($('#TagID').val());
                // remove the current input
                termsk.pop();
                // add the selected item
                termsk.push(ui.item.id);
                // add placeholder to get the comma-and-space at the end
                termsk.push("");
                $('#TagID').val(termsk.join(","));
                return false;
            }
        });


        // end
        // Start Addnew tag
    </script>

</asp:Content>
